<%--
    Document   : listpromotion
    Created on : Nov 17, 2011, 12:22:29 AM
    Author     : Venus
--%>

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
   "http://www.w3.org/TR/html4/loose.dtd">
<%@page import="java.util.*, Beans.ThamSoHT,Models.ThamSoHT_Model"%>
<%
            int langid = (Integer) session.getAttribute("langid"); // ngôn ngữ hiện tại
            String dsts = " 'delete', 'datemsg', 'all', 'promotionname', 'promotionlist', 'promotion', 'disable', 'enable', 'notice', 'order', 'rightmsg', 'status', 'enddate', 'datestart', 'content'  ";
            ThamSoHT[] mdsts = ThamSoHT_Model.DSThamSo(dsts, langid); // mảng chứa các tham số của trang này.

            String all = mdsts[0].getTenTS();
            String content = mdsts[1].getTenTS();
            String datemsg = mdsts[2].getTenTS();
            String datestart = mdsts[3].getTenTS();
            String delete = mdsts[4].getTenTS();
            String disable = mdsts[5].getTenTS();
            String enable = mdsts[6].getTenTS();
            String enddate = mdsts[7].getTenTS();
            String notice = mdsts[8].getTenTS();
            String order = mdsts[9].getTenTS();
            String promotion = mdsts[10].getTenTS();
            String promotionlist = mdsts[11].getTenTS();
            String promotionname = mdsts[12].getTenTS();
            String rightmsg = mdsts[13].getTenTS();
            String status = mdsts[14].getTenTS();

            String msgright = notice + "/" + rightmsg;
            String msgdate = notice + "/" + datemsg;

            Vector v = (Vector) request.getAttribute("DSKM");

            int numpage = 0;// khởi tạo số trang = 0
            int vsize = v.size();
            if (vsize % 6 == 0) // mỗi trang có 6 dòng
            {
                numpage = vsize / 6;
            } else {
                numpage = vsize / 6 + 1;
            }
            String xx = (String) request.getAttribute("item"); // trang hiện tại đang xem
            int item = Integer.parseInt(xx);
            String sapxep = (String) request.getAttribute("order");
            String test = (String) request.getAttribute("test");
            String sort = (String) request.getAttribute("sort");
            String sortkv = (String) request.getAttribute("sortkv");
            String sx1 = "";
            String sx2 = "";
            String sx3 = "";
            String sx4 = "";
            String ud1 = "";
            String ud2 = "";
            String ud3 = "";
            String ud4 = "";
            if(sapxep.equals("desc") ){
                   sx1 = "down";
                   sx2 = "down";
                   sx3 = "down";
                   sx4 = "down";
                   ud1 = "down1";
                   ud4 = "down2";
                   ud2 = "down1";
                   ud3 = "down1";
            }
            
            else if(sapxep.equals("asc") && test.equals("1")){
                    sx1 = "up";
                    sx2 = "down";
                    sx3 = "down";
                    sx4 = "down";
                    ud1 = "up1";
                    ud2 = "down1";
                    ud3 = "down1";
                    ud4 = "down2";
            }
            else if(sapxep.equals("asc") && test.equals("2")){
                    sx1 = "down";
                    sx2 = "up";
                    sx3 = "down";
                    sx4 = "down";
                    ud1 = "down1";
                    ud2 = "up1";
                    ud3 = "down1";
                    ud4 = "down2";
            }           
            else if(sapxep.equals("asc") && test.equals("3")){
                    sx1 = "down";
                    sx2 = "down";
                    sx3 = "up";
                    sx4 = "down";
                    ud1 = "down1";
                    ud2 = "down1";
                    ud3 = "up1";
                    ud4 = "down2";
             }
             else if(sapxep.equals("asc") && test.equals("4")){
                    sx1 = "down";
                    sx2 = "down";
                    sx3 = "down";
                    sx4 = "up";
                    ud1 = "down1";
                    ud2 = "down1";
                    ud3 = "down1";
                    ud4 = "up2";
             }
            String TENKM = (String) request.getAttribute("TENKM");
            String BATDAU = (String) request.getAttribute("BATDAU");
            String KETTHUC = (String) request.getAttribute("KETTHUC");
            String TINHTRANG = (String) request.getAttribute("TINHTRANG");
            int total = 0;
%>
<script type="text/javascript">
    $(function(){
        $('#datepicker1').datepicker($.datepicker.regional['vi']);
        $( "#datepicker1" ).datepicker( "option", "dateFormat","dd/mm/yy");
        $('#datepicker2').datepicker($.datepicker.regional['vi']);
        $( "#datepicker2" ).datepicker( "option", "dateFormat","dd/mm/yy");
     });
</script>
<h1><img style="margin-right: 13px; opacity: 0.8; margin-top: 4px;" alt="" src="../images/promotion11.png"><%=promotion%></h1>
<div class="cb"></div>
<div id="DSKM" class="bloc">
    <div class="title">
        <%=promotionlist%><a href="#" name="1" lang="<%=msgright%>" onclick="TaoKM( this.name, this.lang)" style=" float: right;  margin-top: 3px;" ><img alt="" src="../images/add1.png"></a>
    </div>
    <div class="content">
         <form name="dskm" action="">
             <table class="mytable" border="0" cellpadding="0" cellspacing="0">
                 <thead>
                    <tr>
                        <th style="width: 6%;  "><%=order%></th>
                        <th style="width: 22%; ">
                            <a href="#" id="titledskv1" style="margin-top: 5px;" class="<%=sx1 %>" lang="<%=msgright%>" shape="<%=msgdate%>"  name="1" onclick="SortSearchTenKM(this.className, this.name, this.lang, this.shape)">
                                <div style="float:left"><%=promotionname%></div>
                                <div id="sortkv1" style=" margin-right: 65px;" class="<%=ud1 %>"></div>
                            </a>
                        </th>
                        <th style="width: 14%; ">
                            <a href="#" id="titledskv2" style="margin-top: 5px;" class="<%=sx2 %>" lang="<%=msgright%>" shape="<%=msgdate%>"  name="1" onclick="SortSearchNgayBDKM(this.className, this.name, this.lang, this.shape)">
                                <div style="float:left"><%=datestart%></div>
                                <div id="sortkv2" style=" margin-right: 25px;" class="<%=ud2 %>"></div>
                            </a>
                        </th>
                        <th style="width: 14%; ">
                            <a href="#" id="titledskv3" style="margin-top: 5px;" class="<%=sx3 %>" lang="<%=msgright%>" shape="<%=msgdate%>"  name="1" onclick="SortSearchNgayKTKM(this.className, this.name, this.lang, this.shape)">
                                <div style="float:left"><%=enddate%></div>
                                <div id="sortkv3" style=" margin-right: 20px;" class="<%=ud3 %>"></div>
                            </a>
                        </th>
                        <th style="width: 24%; ">
                            <a href="#" style="margin-top: 5px;" class="down"  name="1" >
                                <div style="float:left; color: #D8DEE1;"><%=content%></div>
                            </a>
                        </th>
                        <th style=" margin-top: 2px;">
                            <a href="#" id="titledskv4" class="<%=sx4 %>"  name="1" lang="<%=msgright%>" shape="<%=msgdate%>" onclick="SortSearchTTKM(this.className, this.name, this.lang, this.shape)">
                                <div><%=status%></div>
                                <div >
                                    <div id="sortkv4" class="<%=ud4 %>"></div>
                                </div>
                            </a>
                        </th>
                        <th></th>
                    </tr>
                    <tr id="searchListKM">
                        <th><img style=" margin-top: 2px; margin-left: 3px; margin-bottom: -7px; cursor: pointer;" lang="<%=msgright%>" alt="1" src="../images/search1.png" id="<%=msgdate%>" onclick="SearchListKM(this.alt, this.lang, this.id)"></th>
                        <th><input type="textbox" style=" width: 120px;" class="TENKM text" value="<%=TENKM%>" ></th>
                        <th><input type="textbox" style=" width: 100px;" id="datepicker1" class="BATDAU text" value="<%=BATDAU %>" ></th>
                        <th><input type="textbox" style=" width: 100px;" id="datepicker2" class="KETTHUC text" value="<%=KETTHUC %>" ></th>
                        <th></th>
                        <th>
                            <div>
                                <select style="height: 22px; "  id="1" class="TINHTRANG text" id="1"  lang="<%=msgright%>" name="<%=msgdate%>" onchange="SearchListKM(this.id, this.lang, this.name)">
                                    <%
                                        if(TINHTRANG.equals("1")){ %>
                                        <option value="1"><%=enable %></option>
                                        <option value="0"><%=disable %></option>
                                        <option value="all"><%=all %></option>
                                    <%    }
                                        else if(TINHTRANG.equals("0")){%>
                                        <option value="0"><%=disable %></option>
                                        <option value="1"><%=enable %></option>
                                        <option value="all"><%=all %></option>
                                    <%  }
                                        else{%>
                                        <option value="all"><%= all %></option>
                                        <option value="1"><%=enable %></option>
                                        <option value="0"><%=disable %></option>
                                    <%    }
                                    %>
                                </select>
                            </div>
                        </th>
                        <th></th>
                    </tr>
                </thead>
                <tbody>
                    <%
                        for (int i = (item - 1) * 6; i < (item - 1) * 6 + 6 && i < vsize; i++) {
                            Beans.KhuyenMai km = (Beans.KhuyenMai) v.elementAt(i);
                            total = total + 1;
                    %>
                    <tr>
                        <td class="STT"><input type="checkbox" value="<%= km.getMaKM()%>" class="optionKM" name="optionKM"></td>
                        <td style="padding-right: 15px;"><a href="#" name="<%=km.getMaKM() %>" lang="<%=msgright%>" onclick="ShowLangKM(this.name, this.lang)"><%= km.getTenKM() %></a></td>
                        <td><%=km.getNgayBD() %></td>
                        <td><%=km.getNgayKT() %></td>
                        <td style="padding-right: 15px;"><%=km.getNoiDungKM() %></td>
                        <td>
                            <select  class="<%= km.getMaKM() %>" lang="<%=msgright%>" onchange="UpdateStatusKV(this.value,  this.className, this.lang)">
                                <%
                                    if (km.getTinhTrang() == 1) {%>
                                        <option value="1"><%= enable%></option>
                                        <option value="0"><%= disable%></option>
                                <%  } else {%>
                                        <option value="0"><%= disable%></option>
                                        <option value="1"><%= enable%></option>
                                <%  }
                                %>
                            </select>
                        </td>
                        <td>
                            <a href="#" name="<%=km.getMaKM() %>" lang="<%=msgright%>" onclick="UpdatePromotion( this.name, this.lang)" style=" float: right; margin-right: 15px; margin-top: 10px;" ><img style="width: 17px; margin-bottom: 7px;" alt="" src="../images/edit.png"></a>
                        </td>
                    </tr>
                    <%  }
                    %>
                    <input type="hidden" name="total" value="<%=total%>">
                </tbody>
             </table>
                <div style="float:left;">
                <input type="button" style="margin-left: 0; margin-top: 5px; margin-bottom: 5px;" class="button" value ="<%=delete%>" lang="<%=msgright%>" id="1"  onclick="DeleteKM( this.id, this.lang)">
            </div>
                <div class="pagination">
                <%
                    int trang = 1;
                    if (item > 1) {
                        trang = item - 1;
                    }
                %>
                <%
                    if (vsize > 10) {%>
                <%
                    if(sortkv.equals("tenkm")){%>
                        <a href="#" id="<%=sort %>" class="prev"  name="<%= trang%>" lang="<%=msgright%>" shape="<%=msgdate%>" onclick="SortSearchTenKM(this.id, this.name, this.lang, this.shape)">«</a>
                <%  }
                    else if(sortkv.equals("ngaybdkm")){%>
                        <a href="#" id="<%=sort %>" class="prev"  name="<%= trang%>" lang="<%=msgright%>" shape="<%=msgdate%>" onclick="SortSearchNgayBDKM(this.id, this.name, this.lang, this.shape)">«</a>
                <%  }
                    else if(sortkv.equals("ngayktkm")){%>
                        <a href="#" id="<%=sort %>" class="prev"  name="<%= trang%>" lang="<%=msgright%>" shape="<%=msgdate%>" onclick="SortSearchNgayKTKM(this.id, this.name, this.lang, this.shape)">«</a>
               <%   }
                    else{%>
                        <a href="#" id="<%=sort %>" class="prev"  name="<%= trang%>" lang="<%=msgright%>" shape="<%=msgdate%>" onclick="SortSearchTTKM(this.id, this.name, this.lang, this.shape)">«</a>
                <%  }
                %>

                <%      for (int c = 1; c <= numpage; c++) {
                            if (c != item) {
                %>
                <%
                    if(sortkv.equals("tenkm")){%>
                        <a href="#" id="<%=sort %>"  name="<%= c%>" lang="<%=msgright%>" shape="<%=msgdate%>" onclick="SortSearchTenKM(this.id, this.name, this.lang, this.shape)" ><%= c%></a>
                <%  }
                    else if(sortkv.equals("ngaybdkm")){%>
                        <a href="#" id="<%=sort %>"  name="<%= c%>" lang="<%=msgright%>" shape="<%=msgdate%>" onclick="SortSearchNgayBDKM(this.id, this.name, this.lang, this.shape)" ><%= c%></a>
                <%  }
                    else if(sortkv.equals("ngayktkm")){%>
                        <a href="#" id="<%=sort %>"  name="<%= c%>" lang="<%=msgright%>" shape="<%=msgdate%>" onclick="SortSearchNgayKTKM(this.id, this.name, this.lang, this.shape)" ><%= c%></a>
               <%   }
                    else{%>
                        <a href="#" id="<%=sort %>"  name="<%= c%>" lang="<%=msgright%>" shape="<%=msgdate%>" onclick="SortSearchTTKM(this.id, this.name, this.lang, this.shape)" ><%= c%></a>
                <%  }
                %>

                <%          } else {%><a class="current"> <%= c%></a> <% }
                        }
                %>
                <%      if (item + 1 <= numpage) {
                            trang = item + 1;
                        } else {
                            trang = item;
                        }
                %>
                <%
                    if(sortkv.equals("tenkm")){%>
                        <a href="#" id="<%=sort %>" class="next"  name="<%= trang%>" lang="<%=msgright%>" shape="<%=msgdate%>" onclick="SortSearchTenKM(this.id, this.name, this.lang, this.shape)">»</a>
                <%  }
                    else if(sortkv.equals("ngaybdkm")){%>
                        <a href="#" id="<%=sort %>" class="next"  name="<%= trang%>" lang="<%=msgright%>" shape="<%=msgdate%>" onclick="SortSearchNgayBDKM(this.id, this.name, this.lang, this.shape)">»</a>
                <%  }
                    else if(sortkv.equals("ngayktkm")){%>
                        <a href="#" id="<%=sort %>" class="next"  name="<%= trang%>" lang="<%=msgright%>" shape="<%=msgdate%>" onclick="SortSearchNgayKTKM(this.id, this.name, this.lang, this.shape)">»</a>
               <%   }
                    else{%>
                        <a href="#" id="<%=sort %>" class="next"  name="<%= trang%>" lang="<%=msgright%>" shape="<%=msgdate%>" onclick="SortSearchTTKM(this.id, this.name, this.lang, this.shape)">»</a>
                <%  }
                %>


                <%  }
                %>
            </div>
         </form>
    </div>
</div>